package cn.xxm.web;

import cn.xxm.pojo.ItemDoc;
import cn.xxm.pojo.RequestParams;
import cn.xxm.service.SearchService;
import com.hmall.clients.ItemClient;
import com.hmall.common.dto.PageDTO;
import com.hmall.common.pojo.Item;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("search")
@Slf4j
public class SearchController {
    @Autowired
    private SearchService service;
    @Autowired
    private ItemClient client;

    @GetMapping("/suggestion")
    public List<String> stringList(@RequestParam("key") String key) {
        return service.getStringList(key);
    }

    @PostMapping("/filters")
    public Map<String, List<String>> filters(@RequestBody RequestParams params) {
        log.info("搜索栏自动补全==前后端==" + params);
        return service.filters(params);
    }
    @PostMapping("/list")
    public PageDTO<ItemDoc> list(@RequestBody RequestParams params){
        log.info("查询结果{}",params);
        return service.listAll(params);
    }
}